<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script>
        //阻止事件的默认行为e.preventDefault（）
        function index(e){
            console.log(111);
            e.preventDefault()
        }
        window.oncontextmenu=function(ex){
            ex.preventDefault()
        }
    </script>
</head>
<body>
    <button oncontextmenu="index(event)">右键点我</button>
    <a href="http://www.baidu.com" onclick="index(event)">百度</a>
    <!-- <a href="javascript:index();">百度</a> -->

</body>
</html>